package net.sx.minemodule.mvp.presenters;

import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;

import net.sx.minemodule.mvp.bean.TestCardBean;
import net.sx.minemodule.mvp.item.AddCardItem;

import java.util.Random;

import io.reactivex.Observable;

/**
 * 选择银行卡
 *
 * @author 11470
 */
public class MinePackageSelectCardPresenter extends AbstractRefreshPresenter<RefreshingView> {

    private Random random;
    private AddCardItem addCardItem;

    public MinePackageSelectCardPresenter(RefreshingView view) {
        super(view);
        random = new Random();

        addCardItem = new AddCardItem();
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        //在这里创建数据
        addSubscription(Observable.range(0, 5)
                .map(integer -> {
                    TestCardBean bean = new TestCardBean();
                    bean.setCardPath("https://picsum.photos/300/300/?random" + random.nextInt());
                    bean.setCardEndNum("1111");
                    bean.setCardName("建设银行");
                    bean.setCardType(1);
                    return bean;
                })
                .toList()
                .subscribe(bean -> {
                    parserData(isLoadMore, bean);
                    adapter.removeItem(footerItem);
                    adapter.addItem(addCardItem);
                    adapter.notifyDataSetChanged();
                }));
    }

}
